package cn.ffcs.bpmpvc.services.impl;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import cn.ffcs.bpmpvc.dao.AppBusinessReqDao;
import cn.ffcs.bpmpvc.dao.BusinessAnalysisDao;
import cn.ffcs.bpmpvc.model.BusinessAnalysis;
import cn.ffcs.bpmpvc.services.BusinessAnalysisService;
import cn.ffcs.bpmpvc.services.bean.ConfigBean;
import cn.ffcs.bpmpvc.utils.FileUtil;
import cn.ffcs.bpmpvc.web.util.UserContextUtil;
import cn.ffcs.common.dao.AttachDAO;
import cn.ffcs.common.model.Attach;
import cn.ffcs.organ.model.Organization;
import cn.ffcs.organ.model.Person;

public class BusinessAnalysisServiceImpl implements BusinessAnalysisService {
	private BusinessAnalysisDao businessAnalysisDao;
	private AppBusinessReqDao appBusinessReqDao;
	private ConfigBean configBean;
	private AttachDAO<Attach> attachDAO;
	public void commitSaveUpload(BusinessAnalysis businessAnalysis,HttpServletRequest request) throws IOException{
		Person person=UserContextUtil.getUserContext(request).getCurrUser().getPerson();
		Organization organization=getAppBusinessReqDao().getOrgByPerson(person.getId());
		businessAnalysis.setOrgId(organization.getId().toString());
		getBusinessAnalysisDao().save(businessAnalysis);
		
		//删除选择的附件
		String attactIdArr[]=request.getParameterValues("attactId");
		if(attactIdArr!=null&&attactIdArr.length>0){
			for (int i = 0; i < attactIdArr.length; i++) {
				attachDAO.deleteById(attactIdArr[i]);
			}
		}
		//保存附件数据
		FileUtil.saveAttaFiles(request, BusinessAnalysis.class.getName(), businessAnalysis.getAppId().toString());
	}
	
	
	public void commitDel(String appId){
		getBusinessAnalysisDao().delBusinessAnalysis(appId);
		getAttachDAO().batchDelAttach(BusinessAnalysis.class.getName(), appId);
	}
	
	public BusinessAnalysisDao getBusinessAnalysisDao() {
		return businessAnalysisDao;
	}
	public void setBusinessAnalysisDao(BusinessAnalysisDao businessAnalysisDao) {
		this.businessAnalysisDao = businessAnalysisDao;
	}
	public AppBusinessReqDao getAppBusinessReqDao() {
		return appBusinessReqDao;
	}
	public void setAppBusinessReqDao(AppBusinessReqDao appBusinessReqDao) {
		this.appBusinessReqDao = appBusinessReqDao;
	}

	public ConfigBean getConfigBean() {
		return configBean;
	}

	public void setConfigBean(ConfigBean configBean) {
		this.configBean = configBean;
	}

	public AttachDAO<Attach> getAttachDAO() {
		return attachDAO;
	}

	public void setAttachDAO(AttachDAO<Attach> attachDAO) {
		this.attachDAO = attachDAO;
	}
	
}
